


** compare to all-indiana
use health/test_daily_panel, clear

** count first positive test per person 
by sid: keep if positive
by sid: keep if _n==1
collapse (sum)  positive, by(date)
rename positive pos_micro
keep if inrange(date, `=mdy(3,6,2020)', `=mdy(12,13,2020)')
merge 1:1 date using data/state_positive_counts, assert(2 3) keep(1 3) nogen

rename positive pos_state 
format date %td

sort date
foreach v of varlist pos_micro pos_state {
	by date: gen avg_`v' = `v'/7
	forvalues l = 1/6 {
		replace avg_`v' = avg_`v' + `v'[_n-`l']/7
	}
}


# delimit ;
twoway

	(line avg_pos_micro date if date >= mdy(3,13,2020), lcolor(black))
	(line avg_pos_state date if date >= mdy(3,13,2020), lcolor(black) lpattern(dash))
	
	(pci 3150 `=mdy(12, 13,2020)' 2150 `=mdy(12,13,2020)', color(black))
	(pci 6400 `=mdy(10,31,2020)' 6400 `=mdy(11,11,2020)', color(black))
	,
	xlabel(`=mdy(3,13,2020)' "3/13" `=mdy(4,13,2020)' "4/13"
		`=mdy(5,13,2020)' "5/13" `=mdy(6,13,2020)' "6/13"
		`=mdy(7,13,2020)' "7/13" `=mdy(8,13,2020)' "8/13" 
		`=mdy(9,13,2020)' "9/13" `=mdy(10,13,2020)' "10/13"
		`=mdy(11,13,2020)' "11/13" `=mdy(12,13,2020)' "12/13")
	text(2000 `=mdy(12,15,2020)' "Our data", place(w))
	text(6400 `=mdy(10,30,2020)' "State dashboard", place(w))
	ylabel(0(2400)7200)
	graphregion(color(white))
	xtitle("")
	legend(off)
;
# delimit cr
graph export figures/compare_to_state.pdf, replace fontface(times)

sum pos_micro 

scalarout using "scratch/total_positives.csv", ///
	id("Micro data count") num(`=r(sum)') fmt(%5.3f) replace
di r(sum)
sum pos_state 
di r(sum)
scalarout using "scratch/total_positives.csv", ///
	id("State data count") num(`=r(sum)') fmt(%5.3f) replace


